home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / games / nhak_src.zip / SEARCH.C < prev    next >
C/C++ Source or Header  |  1993-03-16  |  5KB  |  235 lines

  1. /*    SCCS Id: @(#)search.c    3.0    88/04/13
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6. #ifdef NAMED_ITEMS
  7. #  include "artifact.h"
  8. #endif
  9.  
  10. #ifdef OVLB
  11.  
  12. static void FDECL(findone,(XCHAR_P,XCHAR_P,int *));
  13.  
  14. static void
  15. findone(zx,zy,num)
  16. xchar zx,zy;
  17. int *num;
  18. {
  19.     register struct trap *ttmp;
  20.     register struct monst *mtmp;
  21.  
  22.     if(levl[zx][zy].typ == SDOOR) {
  23.         levl[zx][zy].typ = DOOR;
  24.         levl[zx][zy].seen = 0;
  25.         prl(zx, zy);
  26.         (*num)++;
  27.     } else if(levl[zx][zy].typ == SCORR) {
  28.         levl[zx][zy].typ = CORR;
  29.         levl[zx][zy].seen = 0;
  30.         prl(zx, zy);
  31.         (*num)++;
  32.     } else if(ttmp = t_at(zx, zy)) {
  33.         if(ttmp->ttyp == MONST_TRAP) {
  34.             (void) makemon(&mons[ttmp->pm], zx, zy);
  35.             (*num)++;
  36.             deltrap(ttmp);
  37.         } else if(!ttmp->tseen && ttmp->ttyp != STATUE_TRAP) {
  38.             ttmp->tseen = 1;
  39.             if(!vism_at(zx, zy))
  40.             atl(zx,zy,(char)((ttmp->ttyp==WEB) ? WEB_SYM : TRAP_SYM));
  41.             (*num)++;
  42.         }
  43.     } else if(MON_AT(zx, zy)) {
  44.         mtmp = m_at(zx,zy);
  45.         if(mtmp->mimic) {
  46.                 seemimic(mtmp);
  47.                 (*num)++;
  48.         }
  49.     }
  50. }
  51.  
  52. int
  53. findit()    /* returns number of things found */
  54. {
  55.     int num;
  56.     register xchar zx,zy;
  57.     xchar lx,hx,ly,hy;
  58.     xchar lx2,hx2,ly2,hy2;
  59.  
  60.     if(u.uswallow) return(0);
  61.     if(inroom(u.ux,u.uy) < 0) {
  62.         lx = u.ux - 1;
  63.         hx = u.ux + 1;
  64.         ly = u.uy - 1;
  65.         hy = u.uy + 1;
  66.         lx2 = ly2 = 1;
  67.         hx2 = hy2 = 0;
  68.     } else
  69.         getcorners(&lx,&hx,&ly,&hy,&lx2,&hx2,&ly2,&hy2);
  70.     num = 0;
  71.     for(zy = ly; zy <= hy; zy++)
  72.         for(zx = lx; zx <= hx; zx++)
  73.             if(isok(zx,zy))
  74.                 findone(zx,zy,&num);
  75.     for(zy = ly2; zy <= hy2; zy++)
  76.         for(zx = lx2; zx <= hx2; zx++)
  77.             if(isok(zx,zy))
  78.                 findone(zx,zy,&num);
  79.     return(num);
  80. }
  81.  
  82. #endif /* OVLB */
  83. #ifdef OVL1
  84.  
  85. int
  86. dosearch()
  87. {
  88.     return(dosearch0(0));
  89. }
  90.  
  91. int
  92. dosearch0(aflag)
  93. register int aflag;
  94. {
  95.     register xchar x, y;
  96.     register struct trap *trap;
  97.     register struct monst *mtmp;
  98.     register struct obj *otmp;
  99.  
  100. #ifdef NAMED_ITEMS
  101.     int fund = (spec_ability(uwep, SPFX_SEARCH)) ?
  102.             ((uwep->spe > 5) ? 5 : uwep->spe) : 0;
  103. #endif /* NAMED_ITEMS */
  104.  
  105.     if(u.uswallow) {
  106.         if (!aflag)
  107.             pline("What are you looking for?  The exit?");
  108.     } else
  109.         for(x = u.ux-1; x < u.ux+2; x++)
  110.           for(y = u.uy-1; y < u.uy+2; y++) {
  111.         if(!isok(x,y)) continue;
  112.         if(x != u.ux || y != u.uy) {
  113.             if(levl[x][y].typ == SDOOR) {
  114. #ifdef NAMED_ITEMS
  115.             if(rnl(7-fund)) continue;
  116. #else
  117.             if(rnl(7)) continue;
  118. #endif
  119.             levl[x][y].typ = DOOR;
  120.             levl[x][y].seen = 0;    /* force prl */
  121.             nomul(0);
  122.             prl(x,y);
  123.             } else if(levl[x][y].typ == SCORR) {
  124. #ifdef NAMED_ITEMS
  125.             if(rnl(7-fund)) continue;
  126. #else
  127.             if(rnl(7)) continue;
  128. #endif
  129.             levl[x][y].typ = CORR;
  130.             levl[x][y].seen = 0;    /* force prl */
  131.             nomul(0);
  132.             prl(x,y);
  133.             } else {
  134.         /* Be careful not to find anything in an SCORR or SDOOR */
  135.             if(MON_AT(x, y)) {
  136.                 mtmp = m_at(x,y);
  137.                 if(!aflag && mtmp->mimic) {
  138.                 seemimic(mtmp);
  139.                 You("find %s.", defmonnam(mtmp));
  140.                 return(1);
  141.                 }
  142.             }
  143.  
  144.             for(trap = ftrap; trap; trap = trap->ntrap)
  145.                 if(trap->tx == x && trap->ty == y &&
  146.                 !trap->tseen && !rnl(8)) {
  147.                 nomul(0);
  148.                 if(trap->ttyp != MONST_TRAP &&
  149.                    trap->ttyp != STATUE_TRAP)
  150.                 You("find a%s.", traps[Hallucination ?
  151.                 rn2(TRAPNUM-3)+2 : trap->ttyp ]);
  152.  
  153.                 if(trap->ttyp == MONST_TRAP) {
  154.                     if((mtmp=makemon(&mons[trap->pm], x, y)))
  155.                     You("find %s.", defmonnam(mtmp));
  156.                     deltrap(trap);
  157.                     return(1);
  158.                 } else if(trap->ttyp == STATUE_TRAP) {
  159.                     if((otmp = sobj_at(STATUE, x, y)))
  160.                       if(otmp->corpsenm == trap->pm) {
  161.                         
  162.                     if((mtmp=makemon(&mons[trap->pm], x, y)))
  163.                         You("find %s posing as a statue.",
  164.                           defmonnam(mtmp));
  165.                     delobj(otmp);
  166.                     newsym(x, y);
  167.                       }
  168.                     deltrap(trap);
  169.                     return(1);
  170.                 }
  171.                 trap->tseen = 1;
  172.                 if(!vism_at(x,y))
  173.                     atl(x,y,(char) ((trap->ttyp==WEB)
  174.                         ? WEB_SYM : TRAP_SYM));
  175.                 }
  176.             }
  177.         }
  178.           }
  179.     return(1);
  180. }
  181.  
  182. #endif /* OVL1 */
  183. #ifdef OVLB
  184.  
  185. int
  186. doidtrap() {
  187.     register struct trap *trap;
  188.     register int x,y;
  189.  
  190.     if(!getdir(1)) return 0;
  191.     x = u.ux + u.dx;
  192.     y = u.uy + u.dy;
  193.     for(trap = ftrap; trap; trap = trap->ntrap)
  194.         if(trap->tx == x && trap->ty == y && trap->tseen) {
  195.             if(u.dz)
  196.             if((u.dz < 0) != (is_maze_lev && trap->ttyp == TRAPDOOR))
  197.                 continue;
  198.             pline("That is a%s.",traps[ Hallucination ? rn2(TRAPNUM-3)+3 :
  199.             trap->ttyp]);
  200.             return 0;
  201.         }
  202.     pline("I can't see a trap there.");
  203.     return 0;
  204. }
  205.  
  206. #endif /* OVLB */
  207. #ifdef OVL0
  208.  
  209. void
  210. wakeup(mtmp)
  211. register struct monst *mtmp;
  212. {
  213.     mtmp->msleep = 0;
  214.     mtmp->meating = 0;    /* assume there's no salvagable food left */
  215.     setmangry(mtmp);
  216.     if(mtmp->mimic) seemimic(mtmp);
  217. }
  218.  
  219. #endif /* OVL0 */
  220. #ifdef OVLB
  221.  
  222. /* NOTE: we must check if(mtmp->mimic) before calling this routine */
  223. void
  224. seemimic(mtmp)
  225. register struct monst *mtmp;
  226. {
  227.     mtmp->mimic = 0;
  228.     mtmp->m_ap_type = M_AP_NOTHING;
  229.     mtmp->mappearance = 0;
  230.     unpmon(mtmp);
  231.     pmon(mtmp);
  232. }
  233.  
  234. #endif /* OVLB */
  235.